<?php

namespace App\Admin\Controllers;

use App\Banner;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class BannerController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '广告管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Banner());

        $grid->column('id', __('Id'));
        $grid->column('type', '类型')->using([1=>'banner', 2=>'广告位1', 3=>'会员广告']);
        $grid->column('redirect_type', '跳转类型')->using([1=>'url链接', 2=>'小程序跳转', 3=>'频道页', 3=>'任务详情']);
        $grid->column('status', '状态')->using([-1=>'下架', 0=>'待发布',1=>'在线']);
        $grid->column('created_at', '创建时间');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Banner::findOrFail($id));

        $show->field('id', 'ID');
        $show->imgurl('图片')->image();
        $show->type('类型')->using([1 => 'Banner', 2 => '广告位1', 3 => '会员广告']);
        $show->redirect_type('跳转类型')->using([1 => 'url链接', 2 => '小程序跳转', 3 => '频道页', 3 => '任务详情']);
        $show->field('linkurl', '地址');
        $show->status('状态')->using([-1 => '下架', 1 => '待发布', 2 => '在线']);
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Banner());

        $form->image('imgurl', '图片');
        $form->select('type', '类型')->options([1=>'banner', 2=>'广告位1', 3=>'会员广告']);
        $form->select('redirect_type', '跳转类型')->options([1=>'url链接', 2=>'小程序跳转', 3=>'频道页', 3=>'任务详情']);
        $form->text('linkurl', '链接地址');
        $form->select('status', __('Status'))->options([-1=>'下架', 0=>'待发布',1=>'在线']);

        return $form;
    }
}
